import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_class2/common/global.dart';

Widget newsCard(String imagePath, String title, String date, String author_name) {
  final currentColor = Colors.white70;//统一卡片与边框的颜色

  final newsTitle = Container(
    width: Global.screenWidth - 25*2 - 120 - 20 - 60, // 根据屏幕尺寸调整文本尺寸
    child:Text(
      title,
      softWrap: true,
      maxLines: 2,
      overflow: TextOverflow.ellipsis,//设置字符过长时显示省略号
      style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),
    ),
  );

  final newsDateAndAuthor = Container(
    width: Global.screenWidth - 25*2 - 120 - 20 - 60,
    child: Text(
      date,
      // date + "  " + author_name,
      softWrap: true,
      maxLines: 1,
      textAlign: TextAlign.end,
      overflow: TextOverflow.ellipsis,//在写死container宽度的基础上设置字符过长时显示省略号
      style: TextStyle(),
    ),
  );

  return Container(
    height: 120,
    alignment: Alignment.center,
    decoration: BoxDecoration(
      color: currentColor,//背景色
      borderRadius: BorderRadius.all(Radius.circular(0.0)),//设置四周圆角 角度
      border: new Border.all(width: 0, color: currentColor),//设置四周边框
    ),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Padding(
            padding: EdgeInsets.all(5.0),
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(0.0)),
              child: Image.network(imagePath),
            ),
        ),
        SizedBox(width: 5,),
        Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween, // 将主轴空白位置进行均分，排列子元素，首尾没有空隙
          crossAxisAlignment: CrossAxisAlignment.start,// 将主轴元素左对齐
          children: [
            Padding(
                padding: EdgeInsets.only(top: 5),
                child: newsTitle
            ),
            Padding(
                padding: EdgeInsets.only(bottom: 5),
                child: newsDateAndAuthor,
            ),
          ],
        ),
      ],
    ),
  );
}